<template>
  <el-container>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="分类名称">
        <el-input placeholder="请输入内容" v-model="form.name"></el-input>
      </el-form-item>

      <el-form-item label="服务封面">
        <el-input placeholder="请输入内容" v-model="form.icon"></el-input>
      </el-form-item>

      <el-form-item label="是否显示">
        <el-switch
          v-model="form.show"
          active-text="是"
          inactive-text="否"
          active-value="1"
          inactive-value="0"
        ></el-switch>
      </el-form-item>

      <el-form-item label="排序">
        <el-input
          type="number"
          placeholder="0-999"
          v-model="form.sort"
        ></el-input>
        <span style="color: #606266">数值越大，排序越靠前</span>
      </el-form-item>

      <el-form-item label="显示数量">
        <el-input
          type="number"
          placeholder=""
          v-model="form.showNumber"
        ></el-input>
        <span style="color: #606266">首页显示二级分类的数量</span>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </el-container>
</template>

<script>
import { createYzKind } from "@/api/yzKind";

export default {
  mounted() {},
  data() {
    return {
      form: {
        name: "",
        icon: "",
        show: "0",
        sort: "",
        showNumber: "",
      },
    };
  },
  methods: {
    onSubmit() {
      createYzKind(this.form)
        .then((response) => {
          this.$message({
            message: response.data.msg,
            type: "success",
          });
          this.form = {
            name: "",
            icon: "",
            show: "0",
            sort: "",
            showNumber: "",
          };
        })
        .catch((response) => {
          this.$message.error(response.data.msg);
          this.form = {
            name: "",
            icon: "",
            show: "0",
            sort: "",
            showNumber: "",
          };
        });
    },
    resetForm() {
      this.form = {
        name: "",
        icon: "",
        show: "0",
        sort: "",
        showNumber: "",
      };
    },
  },
};
</script>